﻿using M.Warehouse.API.Application.Command.FinishedProductCommand;
using M.Warehouse.Repository.WarehouseInterface;
using MediatR;

namespace M.Warehouse.API.Application.CommandHandlers.FinishedProductHandlers
{
    public class FinishedProductDeleteCommandHandlers : IRequestHandler<FinishedProductDeleteCommand, int>
    {
        private readonly IFinishedProductRepository _finishedProductRepository;
        public FinishedProductDeleteCommandHandlers(IFinishedProductRepository finishedProductRepository)
        {
            _finishedProductRepository = finishedProductRepository;
        }
        /// <summary>
        /// 删除成品
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(FinishedProductDeleteCommand request, CancellationToken cancellationToken)
        {
            var del = await _finishedProductRepository.GetModelAsync(request.FinishedProductId);
            del.IsDeleted = true;
            return await _finishedProductRepository.Update(del);
        }
    }
}
